# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=merlin-server
pkgver=1.3.0
pkgrel=1
pkgdesc='Merlin is a cross-platform post-exploitation HTTP/2 Command & Control server and agent written in golang.'
groups=('blackarch' 'blackarch-automation' 'blackarch-exploitation')
arch=('x86_64')
url='https://github.com/Ne0nd0g/merlin'
license=('GPL3')
makedepends=('p7zip' 'wget')
source=("$pkgname.7z::https://github.com/Ne0nd0g/merlin/releases/download/v$pkgver/merlinServer-Linux-x64.7z")
sha512sums=('429be798d31584fb136203c52ccc09f87e920eac2e4f19803de8e2a76ca6ff084a85f95ba2e7cc2238fddb8c5cefcb557b165aa3290daaeb5622c4be49cb5494')

prepare() {
  install -dm 755 $pkgname

  cd $pkgname

  7z -y x -o"$srcdir/$pkgname" -p'merlin' \
   "$srcdir/$pkgname.7z"

  rm -rf "$srcdir/$pkgname.7z"
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.MD
  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/merlin-server/LICENSE"

  cp -a docs/* "$pkgdir/usr/share/doc/$pkgname/"

  rm -rf docs LICENSE README.MD

  cp -a * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
./merlinServer-Linux-x64 "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

